package sns.action;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import sns.bean.User;
import sns.service.MblogService;
import sns.service.RecommendService;
import sns.service.RelationService;
import sns.service.UserService;
import sns.util.RecommendUser;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class SearchAction extends ActionSupport {

	// injection
	private UserService userService;
	private MblogService mblogService;
	private RelationService relationService;
	private RecommendService recommendService;

	// pass in
	private String searchContent;

	// return value
	private List<User> relatedUser;
	private List<User> recentFollowerList;
	private List<User> recentFolloweeList;
	private List<User> hotList;
	private User currentUser;
	private Integer numberOfFollowers;
	private Integer numberOfFollowees;
	private Integer numberOfBlogs;
	private Long userId;
	private User actualUser;
	private List<RecommendUser> recommendList;

	// parameter

	@Transactional
	public String execute() {

		currentUser = userService.getCurrentUser();
		userId = currentUser.getIduser();
		actualUser = currentUser;
		// get all the blogs including mine and followees
		recentFolloweeList = userService.getNFollowees(currentUser, 5);
		recentFollowerList = userService.getNFollowers(currentUser, 5);
		recommendList = recommendService.recommendUsers(currentUser, 10);
		hotList = userService.getHotUsers(10);
		numberOfBlogs = mblogService.getMblogNum(currentUser);
		numberOfFollowees = relationService.getFolloweeNum(currentUser);
		numberOfFollowers = relationService.getFollowerNum(currentUser);

		System.out.println("################hahahahahah content is "
				+ searchContent);

		relatedUser = userService.queryUser(searchContent);
		return Action.SUCCESS;
	}

	public void setRelationService(RelationService relationService) {
		this.relationService = relationService;
	}

	public List<User> getRecentFollowerList() {
		return recentFollowerList;
	}

	public List<User> getRecentFolloweeList() {
		return recentFolloweeList;
	}

	public List<User> getHotList() {
		return hotList;
	}

	public User getCurrentUser() {
		return currentUser;
	}

	public Integer getNumberOfFollowers() {
		return numberOfFollowers;
	}

	public Integer getNumberOfFollowees() {
		return numberOfFollowees;
	}

	public Integer getNumberOfBlogs() {
		return numberOfBlogs;
	}

	public Long getUserId() {
		return userId;
	}

	public void setMblogService(MblogService mblogService) {
		this.mblogService = mblogService;
	}

	public void setSearchContent(String searchContent) {
		this.searchContent = searchContent;
	}

	public void setRelatedUser(List<User> relatedUser) {
		this.relatedUser = relatedUser;
	}

	public List<User> getRelatedUser() {
		return relatedUser;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public void setActualUser(User actualUser) {
		this.actualUser = actualUser;
	}

	public User getActualUser() {
		return actualUser;
	}

	public void setRecommendList(List<RecommendUser> recommendList) {
		this.recommendList = recommendList;
	}

	public void setRecommendService(RecommendService recommendService) {
		this.recommendService = recommendService;
	}

	public List<RecommendUser> getRecommendList() {
		return recommendList;
	}

}
